
struct node
{
	int u,a;
	node(){}
	node(int aa,int bb)
	{ u=aa; a=bb;}
	bool operator<(const node &b)const
	{	return a>b.a;}
};
priority_queue<node>q;int dis[maxv];
int spfa()
{
	while(!q.empty())	q.pop();
	memset(dis,-1,sizeof(dis));
	int i,j,e,s=S,t=T;
	dis[s]=0;
	node a;
	q.push(node(s,0));
	while(!q.empty())
	{
		a=q.top(); q.pop();
		int u=a.u;
		if(a.u==T)	return dis[T];
		for(e=first[u]; e!=-1; e=next[e])
		{
			int v=E[e];
			if(dis[u]+C[e]<dis[v]||dis[v]==-1)
			{
				dis[v]=dis[u]+C[e];
				q.push(node(v,dis[v]));
			}
		}
	}
}
